package com.cnap.multiclouldmgmt.controller;

import com.cnap.multiclouldmgmt.MulticlouldmgmtApplicationTests;
import com.cnap.multiclouldmgmt.model.RepByPage;
import com.cnap.multiclouldmgmt.model.k8sModels.K8sClusterModel;
import com.cnap.multiclouldmgmt.service.MultiCloudMgmtService;
import com.cnap.multiclouldmgmt.service.OperationLogService;
import com.cnap.multiclouldmgmt.util.FileUtils;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.*;

class MultiCloudMgmtControllerTest extends MulticlouldmgmtApplicationTests {

    @MockBean
    private MultiCloudMgmtService multiCloudMgmtService;

    @MockBean
    private OperationLogService operationLogService;

    @Autowired
    private MultiCloudMgmtController multiCloudMgmtController;

    @Test
    void getK8sClusterInfos() {

        RepByPage<K8sClusterModel> k8sClusterModelRepByPage = new RepByPage<>();
        Mockito.when(multiCloudMgmtService.getK8sClusterInfos("aliyun","clustername",10,1))
                        .thenReturn(k8sClusterModelRepByPage);
        multiCloudMgmtController.getK8sClusterInfos("aliyun","clustername",10,1,null,null);
    }

    @Test
    void addK8sCluster() {

        MultipartFile k8sConfigFile = new MockMultipartFile("abc","ddffa".getBytes(StandardCharsets.UTF_8));
        multiCloudMgmtController.addK8sCluster(k8sConfigFile,"aliyun","1.1.1.1","clustername",
                                "aaa","js","1","0");

    }

    @Test
    void addK8sClusterByToken() {

        K8sClusterModel k8sClusterModel = new K8sClusterModel();
        k8sClusterModel.setK8sClusterName("clustername");
        multiCloudMgmtController.addK8sClusterByToken(k8sClusterModel);
    }

    @Test
    void editK8sClusterInfo() {

        K8sClusterModel k8sClusterModel = new K8sClusterModel();
        k8sClusterModel.setK8sClusterName("clustername");
        multiCloudMgmtController.editK8sClusterInfo(k8sClusterModel);
    }

    @Test
    void delK8sCluster() {

        multiCloudMgmtController.delK8sCluster("aliyun","1.1.1.1");
    }
}